import { assetManager, Button, Node } from "cc";
import { App } from "../../App";
import { MyEvent } from "../../frame/common/event/MyEvent";
import { IViewCtrl, TViewConfig, ViewId, ViewLayer } from "../../frame/common/view/IView";
import { ViewCtrlBase } from "../../frame/common/view/ViewCtrlBase";
import { MyBundleName } from "../../frame/mgr/BundleMgr";
import { DemoPageView } from "./DemoPageView";


export class DemoPageCtrl extends ViewCtrlBase implements IViewCtrl {


    model: any;

    get view(): DemoPageView {
        return this._view;
    }

    parseDep(): void {

    }
    listClickButtons(): Node[] {
        return null;
    }

    protected onShow(): void {
        super.onShow();

        this.showTitle();
    }
  
    showTitle():void{
        const chain = this.viewMgr.getViewChain(this.config.id);
        let str = "";
        let name = this.getName(chain.shift());
        str += `我是${name}\n\n`;
        for (let i = 0; i <= chain.length - 1; i++) {
            name = this.getName(chain[i]);
            str += `往上一层是${name}\n\n`;
        }

        this.view.showTitle(str);
    }

    getName(viewId: ViewId): string {
        const ctrl = this.viewMgr.getCtrl(viewId);
        return ctrl.config.label;
    }

}